﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Domain;
using Warehouse.ErrorCord;
using Warehouse.Write.Api.Actions.Warehouse.Command;

namespace Warehouse.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehousController : ControllerBase
    {
        private readonly IMediator mediator;

        public WarehousController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 仓库添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<WarehouseInformation>> AddInformation(AddInformationCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 仓库类别添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<WarehouseCategory>> AddCategory(AddWarehouseCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 仓库删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<WarehouseInformation>> DelInformation([FromQuery]DelinformationCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 仓库类别删除
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<WarehouseCategory>> DelCategoy([FromQuery]DelCategoryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改仓库类别信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<WarehouseCategory>> UpdCategory(UpdCategoryCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改仓库信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<WarehouseInformation>> UpdInformation(UpdInformationCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
